home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / INT24H.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-09-20  |  3.8 KB  |  152 lines

  1. ;*****************************************************************************
  2. ; INT24H.ASM          Example:  handing critical errors from DOS.
  3. ;
  4. ;
  5. ; This program will hook interrupt 24h which is the DOS critical
  6. ; error handler. DOS32 automatically redirect INT 24h from real mode to
  7. ; INT 24h in protected mode. In other words, your programs may handle  
  8. ; DOS critical errors simply by hooking interrupt 24h.
  9. ; Normally the command interpreter ( e.g COMMAND.COM ) hooks this interrupt
  10. ; and displays a message on the screen asking the user to Abort, Ignore,
  11. ; Fail or Retry the operation.
  12. ;      The protected mode critical error handler below works in a similar
  13. ; way except it does not allow to (A)bort since this will terminate the
  14. ; application without exiting from protected mode properly.
  15. ;
  16. ;*****************************************************************************
  17.  
  18. .386
  19. .model flat
  20. .stack 1024
  21.  
  22. .data
  23. Old_Int24h_vector       DF ?
  24. return_code             db ?
  25. dummystring             db 256 dup (?)
  26.  
  27.  
  28. .code
  29. mesg1        db ' Please remove disk from drive A, so that the INT 24h critical error is called.'
  30.              db 13,10,13,10,'Press any key ...',13,10,36
  31. exit_mesg    db 'Program is exiting ',13,10,36
  32.  
  33.  
  34. start:
  35.  
  36.  
  37.   ;
  38.   ; Save the INT 24h vector before we modify it
  39.   ;
  40.     mov     ax,204h
  41.     mov        bl,24h
  42.     int     31h
  43.     Mov     Dword ptr Old_Int24h_vector,edx
  44.     Mov     Word ptr Old_Int24h_vector[4],cx
  45.  
  46.   ;
  47.   ; Set INT 24h vector point to our critical error handler ( see below )
  48.   ;
  49.     mov     ax,205h
  50.     mov        bl,24h
  51.     mov        cx,cs
  52.     mov     edx,Offset  Int24h_Handler
  53.     int     31h
  54.  
  55.  
  56.  
  57.   ; Display a message to let the user know the critical error handler
  58.   ; is about to be invoked.
  59.   ;
  60.     mov     edx,offset mesg1
  61.     mov     ah,9
  62.     int     21h
  63.     mov     ah,0            ; wait for a key
  64.     int     16h
  65.  
  66.  
  67.   ;
  68.   ; Access drive A just to make DOS invoke a critical error (INT 24h)
  69.   ;
  70.     mov     ah,47h                               ; get CWD
  71.     mov     esi,offset dummystring
  72.     mov     dl,1
  73.     int     21h
  74.  
  75.  
  76.    ;
  77.    ; Restore the origonal INT 24h vector
  78.    ;
  79.     mov     ax,204h
  80.     mov        bl,24h
  81.     Mov     edx,Dword ptr Old_Int24h_vector
  82.     Mov     cx,Word ptr Old_Int24h_vector[4]
  83.     int     31h
  84.  
  85.  
  86.    ;
  87.    ; Exit program with a message.
  88.    ;
  89.         mov     edx,offset exit_mesg
  90.         mov     ah,9
  91.         int     21h
  92.         mov     ax,4c00h
  93.         int     21h
  94.  
  95.  
  96. ;************************************************************************
  97. ;
  98. ; INTERRUPT 24H --CRITICAL ERROR HANDLER--
  99. ;
  100. ;************************************************************************
  101. Int24h_Handler PROC FAR
  102.         push     ds                                 ; Save registers used
  103.         pushad
  104.         mov        ax,_DATA                           ; load DS with data selector
  105.         mov     ds,ax
  106.  
  107.         mov     edx,offset Error_message
  108.         mov     ah,9
  109.         int     21h
  110.  
  111.   ; Loop around to read the keyboard
  112.   ;
  113.  
  114. getkeyLOOP:
  115.         mov     ah,0            ; get bios key
  116.         int     16h
  117.         cmp     ah,17h
  118.         jne  J09
  119.          mov    return_code,0   ; ignore
  120.          jmp gotkey
  121. J09:
  122.         cmp     ah,21h
  123.         jne  J08
  124.          mov    return_code,3   ; Fail
  125.          jmp gotkey
  126. J08:
  127.         cmp     ah,13h
  128.         jne  J07
  129.          mov    return_code,1   ; Try again
  130.          jmp gotkey
  131. J07:
  132.     jmp getkeyLOOP
  133. gotkey:
  134.  
  135.         popad
  136.         mov     al,return_code
  137.         pop     ds
  138.         iretd                    ; Return from the interrupt.
  139.  
  140. Error_message  LABEL BYTE
  141. db 13,10
  142. db ' This message has been printed by the INT 24h critical error handler.',13,10
  143. db '  Please select one of the following actions ',13,10
  144. db '  F) fail',13,10
  145. db '  R) retry',13,10
  146. db '  I) ignore',13,10
  147. db '$'
  148.  
  149. Int24h_Handler ENDP
  150.  
  151. end start
  152.